package com.dc.adaptor.passive;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class QueueFactory {
	
	private static final Map<String, BlockingQueue<Message>> queueCache = new HashMap<String, BlockingQueue<Message>>();
	
	public static BlockingQueue<Message> getQueue(String key){
		BlockingQueue<Message> queue = queueCache.get(key);
		if(queue==null){
			synchronized (queueCache) {
				queue = queueCache.get(key);
				if(queue==null){
					queue = new LinkedBlockingQueue<Message>();
					queueCache.put(key, queue);
				}
			}
		}
		return queue;
	}
	
	public static synchronized void removeQueue(String key){
		queueCache.remove(key);
	}
	
}
